/*
 * Copyright (C) 2012 SeekDeepWithin.com
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
package com.seekdeepwithin.Data;

/**
 * User: Jonathan Montiverdi Date: Oct 4, 2012
 *
 * Represents a link in Seek Deep Within.
 */
public class ReadLink
{
   private String m_FullLink;
   private String m_Text;
   private String m_Book;
   private String m_SubBook;
   private String m_Chapter;
   private String m_Verse;

   /**
    * Initializes a new link.
    * @param fullLink ReadLink's full path.
    */
   public ReadLink (String fullLink)
   {
      this.m_Text = "";
      this.m_Book = "";
      this.m_Verse = "";
      this.m_SubBook = "";
      this.m_Chapter = "";
      this.m_FullLink = fullLink;
      this.Parse ();
   }

   /**
    * Gets the text to display for the link.
    * @return The string representation of the link.
    */
   public String getText ()
   {
      return m_Text;
   }

   /**
    * Sets the links text to display.
    * @param Text Text to display for the link.
    */
   public void setText (String Text)
   {
      this.m_Text = Text;
   }

   /**
    * Gets the full link.
    * @return The full path of the link.
    */
   public String getFullLink ()
   {
      return m_FullLink;
   }

   /**
    * Gets the book the link is referring to.
    * @return The book the link is referring to.
    */
   public String getBook ()
   {
      return this.m_Book;
   }

   /**
    * Gets if the link as a book or not.
    * @return True if a book was parsed out of the link, otherwise false.
    */
   public boolean hasBook ()
   {
      return !this.m_Book.isEmpty ();
   }

   /**
    * Gets the sub book the link is referring to.
    * @return The sub book the link is referring to.
    */
   public String getSubBook ()
   {
      return this.m_SubBook;
   }

   /**
    * Gets if the link as a sub book or not.
    * @return True if a sub book was parsed out of the link, otherwise false.
    */
   public boolean hasSubBook ()
   {
      return !this.m_SubBook.isEmpty ();
   }

   /**
    * Gets the chapter the link is referring to.
    * @return The chapter the link is referring to.
    */
   public String getChapter ()
   {
      return this.m_Chapter;
   }

   /**
    * Gets if the link as a chapter or not.
    * @return True if a chapter was parsed out of the link, otherwise false.
    */
   public boolean hasChapter ()
   {
      return !this.m_Chapter.isEmpty ();
   }

   /**
    * Gets the verse the link is referring to.
    * @return The verse the link is referring to.
    */
   public String getVerse ()
   {
      return this.m_Verse;
   }

   /**
    * Gets if the link as a verse or not.
    * @return True if a verse was parsed out of the link, otherwise false.
    */
   public boolean hasVerse ()
   {
      return !this.m_Verse.isEmpty ();
   }

   /**
    * Implements the to string method.
    * @return The string representation of the link.
    */
   @Override
   public String toString ()
   {
      return this.getText ();
   }

   /**
    * Attempts to parse the link.
    * @param fullLink The link to parse.
    */
   private void Parse ()
   {
      if (this.m_FullLink.isEmpty ()) {
         return;
      }
      if (!this.m_FullLink.contains (":")) {
         return;
      }
      String[] linkSplit = this.m_FullLink.split (":");
      this.m_Book = linkSplit[0];
      this.m_SubBook = linkSplit[1];
      if (linkSplit.length == 4) {
         this.m_Chapter = linkSplit[2];
         this.m_Verse = linkSplit[3];
      } else if (linkSplit.length == 3) {
         this.m_Chapter = linkSplit[2];
      }
   }
}
